package cn.controlsys.service.impl;

import cn.controlsys.common.constants.HttpCode;
import cn.controlsys.common.constants.HttpConstant;
import cn.controlsys.common.entity.RequestResult;
import cn.controlsys.dao.RechargeAccountMapper;
import cn.controlsys.dao.RechargeProductMapper;
import cn.controlsys.model.RechargeAccount;
import cn.controlsys.model.RechargeProduct;
import cn.controlsys.operationDao.HouseResourceMapper;
import cn.controlsys.service.RechargeAccountService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @Description: Created by Administrator on 2018/12/25.
 * 暂时没有用了，这个在运营系统那边直接添加了
 */
@Service
public class RechargeAccountServiceImpl implements RechargeAccountService {
    @Autowired
    RechargeProductMapper rechargeProductMapper;
    @Autowired
    RechargeAccountMapper rechargeAccountMapper;
    @Autowired
    HouseResourceMapper houseResourceMapper;

    @Override
    public RequestResult initRechargeAccount(String wecAccount, String city, String company, String type,String rechargeType,String houseOperationNumber) {
        String productid = rechargeProductMapper.selectProductId(city,company);
        if(StringUtils.isBlank(productid)){
            return new RequestResult(HttpConstant.HTTP_CODE_SAVE_ERROR,"缴费产品编号不存在",null);
        }
        List<RechargeAccount> rechargeAccountList = rechargeAccountMapper.selectRechargeAccountByWecAccount(wecAccount,Byte.valueOf(type));
        if(!CollectionUtils.isEmpty(rechargeAccountList)){
            return new RequestResult(HttpConstant.HTTP_CODE_SAVE_ERROR,"户号缴费信息已经存在",null);
        }
        if(StringUtils.isBlank(houseOperationNumber)){
            houseOperationNumber = houseResourceMapper.getHouseOperationNumberByAccount(wecAccount);
        }
        System.out.println("houseOperationNumber："+houseOperationNumber);
        RechargeAccount rechargeAccount = new RechargeAccount();
        rechargeAccount.setProductId(productid);
        rechargeAccount.setWecAccount(wecAccount);
        rechargeAccount.setWecType(Byte.valueOf(type));
        rechargeAccount.setRechargeType(Byte.valueOf(rechargeType));
        rechargeAccount.setHouseOperationNumber(houseOperationNumber);
        rechargeAccountMapper.insertSelective(rechargeAccount);
        return new RequestResult(HttpConstant.HTTP_CODE_SUCCESS,"添加成功",null);
    }
}
